from config import REQUEST_FORMAT_CODE

from copy import deepcopy
def item2dict(item, filter=[], choose=[]):
    if isinstance(item, list):
        datas = []
        for i in item:
            datas.append(item2dict(i, filter, choose))
            print('数据加工过程\n',datas)
        return datas

    data = deepcopy(item.__dict__)   #为什么要是用深拷贝
    # for k,v in data.items():
    #     if isinstance(v,Decimal):
    #         data[k]=float(v)
        # print(type(v))
    data.pop('_sa_instance_state')
    if choose:
        return {k: data.get(k) for k in choose}
    for i in filter:
        data.pop(i)
    return data

def my_route(code, data={}):
    return {'code': code, 'msg': REQUEST_FORMAT_CODE.get(code, 407), 'data': data}
